package com.whmall.service.crm.module.supplierchemical.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.whmall.service.crm.entity.dto.supplierchemical.ChemicalCoaInfoReqDTO;
import org.springframework.stereotype.Component;

/**
 * Description TODO
 * @Author yangkuan
 * Date 2020/9/18 17:30
 **/
@Component
public class ChemicalCoaInfoValidator {

    public void validate(ChemicalCoaInfoReqDTO chemicalCoaInfoReqDTO) {

        if (chemicalCoaInfoReqDTO.getBatchNo() == null){
            throw new IllegalArgumentException("批次号不能为空");
        }

        if (StrUtil.isEmpty(chemicalCoaInfoReqDTO.getConclusion())){
            throw new IllegalArgumentException("结论不能为空");
        }

        if (chemicalCoaInfoReqDTO.getProductionDate() == null){
            throw new IllegalArgumentException("生产日期不能为空");
        }

        if (chemicalCoaInfoReqDTO.getLastTestDate() == null){
            throw new IllegalArgumentException("最后检测日期不能为空");
        }

        if (StrUtil.isEmpty(chemicalCoaInfoReqDTO.getCoaUrl())){
            throw new IllegalArgumentException("产品附件不能为空");
        }

        if (CollUtil.isEmpty(chemicalCoaInfoReqDTO.getCoaRecordReqs())){
            throw new IllegalArgumentException("项目/指标/结果不能为空");
        }

        chemicalCoaInfoReqDTO.getCoaRecordReqs().forEach(chemicalCoaRecordReqDTO -> {
            if (StrUtil.isEmpty(chemicalCoaRecordReqDTO.getItem())){
                throw new IllegalArgumentException("项目不能为空");
            }
            if (StrUtil.isEmpty(chemicalCoaRecordReqDTO.getMetric())){
                throw new IllegalArgumentException("指标不能为空");
            }
            if (StrUtil.isEmpty(chemicalCoaRecordReqDTO.getResult())){
                throw new IllegalArgumentException("结果不能为空");
            }
        });

    }

}
